var map = {}
var selectCol=new Array();
$(document).ready(function(){  
	$("#functionNav").attr("href",navAddr);
	//获取查询条件

	dxjbJson = ajaxResult("get",false,ProjectName+"/sysmanage.getIdAndNameInjb.do", {"tableName":'jb_xfjb'});
	dxjbJson = dxjbJson.rows;
	loadSelect("#dxjb",dxjbJson,'id','name');
	
	getUserRight();
	dxyyJson = ajaxResult("get",false,ProjectName+"/sysmanage.getIdAndNameInjb.do", {"tableName":'jb_xfyy'});
	dxyyJson = dxyyJson.rows;
	loadSelect("#dxyy",dxyyJson,'id','name');
	
	

	var kfJson = ajaxResult("get",false,ProjectName+"/sysmanage.getkfIdNameBybgyId.do",{'bgyId':userInfo.userid});
	loadSelect("#szkf",kfJson.rows,'kfid','kfmc');
	
	
	$("#lrrid").val(userInfo.userid);
	$("#lrrmc").val(userInfo.username);
	$("#lrsj").val(nowDate());
	
	createTableByJson('#TempColTable',selectCol,tempTitle,'id');	
	$("#importCp").click(function(){
		$("#importlistModal").modal('show');
		var params =$("#form_importlist").serializeObject();
		createTable('#importColTable',ProjectName+'/colrepair.getListByZrbgyPagging.do','id',importlistTitle,params);	
		refreshTable('#importColTable','#form_importlist');
	 });
	
	
	//点击查询按钮
	 $("#mod_importcol_btn").click(function(){
		 var ids = selDataIds("#importColTable");
		 if(ids.length == 0){
			 alertFunc("请选择记录！");
			 return false;
		 }
		 bootbox.setLocale("zh_CN");
		 bootbox.confirm("您确定导入？",function(r){
			 if(r){
				 var selectData = $("#importColTable").bootstrapTable('getSelections');
				 $.each(selectData,function(index,value){
					 map[value["zdjh"]]=value;
				 });
				 $("#importlistModal").modal('hide');	
				 $('#TempColTable').bootstrapTable('destroy');	
				 
				 selectCol=new Array();
				 $.each(map,function(index,value){
					 selectCol.push(value);
				 });
				 createTableByJson('#TempColTable',selectCol,tempTitle,'id');
			 }
		 });
	 });
	 $("#saveDxcp").click(function(){
		 selectCol=new Array();
		 $.each(map,function(index,value){
			 selectCol.push(value["zdjh"]);
		 });
		 if(selectCol.length == 0){
			 alertFunc("没有选择任何藏品！");
			 return false;
		 }
//		 var dxjb = $("#dxjb").val();
//		 var dxyy = $("#dxyy").val();
//		 if(dxyy==""||dxjb==""){
//			 alertFunc("待修原因和待修级别不能为空！");
//			 return false;
//		 }
		 var params =$("#form_adddxcp").serializeObject();
		 params["zdjh"]=selectCol+"";
		 var detail = ajaxResult("get",false,ProjectName+"/colrepair.saveColWaitingRepair.do",params);
		 if(detail.status=="ok"){
			 alert("保存成功");
			 window.location.href = "dxcplist.html";
		 }else{
			 alert("保存失败")
		 }
	 });
	 $("#goback").click(function(){
		 window.location.href = "dxcplist.html";
	 });
	 

	 $("#mod_query_btn").click(function(){
		 refreshTable('#importColTable','#form_importlist');
	 });
})

var importlistTitle = [{
    checkbox: true
}, {
	field: 'zdjh',
	title: '藏品总登记号'
},{
	field: 'flh',
	title: '分类号'
},{
	field: 'cpmc',
	title: '藏品名称'
},{
	field: 'cpfl1',
	title: '藏品分类'
},{
	field: 'cpjb',
	title: '藏品级别'
}]

var tempTitle = [{
	field: 'zdjh',
	title: '藏品总登记号'
},{
	field: 'flh',
	title: '分类号'
},{
	field: 'cpmc',
	title: '藏品名称'
},{
	field: 'cpfl1',
	title: '藏品分类'
},{
	field: 'cpjb',
	title: '藏品级别'
}]